package com.grape.demo_graphql.resolver.mutation;

import com.grape.demo_graphql.entity.BankAccount;
import com.grape.demo_graphql.entity.CreateBankAccountInput;
import com.grape.demo_graphql.entity.Currency;
import graphql.kickstart.tools.GraphQLMutationResolver;
import graphql.schema.DataFetchingEnvironment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.UUID;

/**
 * @author robin
 * @Date 2021/11/4
 * @Description
 */
@Slf4j
@Component
@Validated
public class BankAccountMutation implements GraphQLMutationResolver {
    public BankAccount createBankAccount(@Valid CreateBankAccountInput accountInput, DataFetchingEnvironment env){

        if (env.getSelectionSet().contains("id")){
            log.info("select id from database");
        }
        return BankAccount.builder()
                .id(UUID.randomUUID())
                .currency(Currency.RMB)
                .createdAt(OffsetDateTime.now())
                .createOn(LocalDate.now())
                .build();
    }
}
